package ctr;

import java.util.ArrayList;

import model.Guest;
import model.Room;
import model.RoomReservation;
import db.DbConnection;
import db.DbRRBuffer;
//import db.DbConnection;
import db.DbRoom;
import db.DbRoomReservation;

public class RRctr {
	
	public ArrayList<Room> findEmptyRooms(String checkIn, String checkOut)
    {
      DbRoom dbr = new DbRoom();
      ArrayList<Room> allp = dbr.getEmptyRooms(checkIn, checkOut);
      return allp;
    }
	
	public ArrayList<Room> findAllRooms()
	{
		DbRoom dbr = new DbRoom();
		ArrayList<Room> allp = dbr.getAllRooms(false);
		return allp;
		
	}
	
	public ArrayList<RoomReservation> findAllReservation()
	{
		DbRoomReservation dbr = new DbRoomReservation();
		ArrayList<RoomReservation> allp = dbr.getAllRoomReservations(false);
		return allp;
	}
	
	public void insertNew(String status, String checkIn, String checkOut, int guestId)
    {    
		 
         RoomReservation oObj = new RoomReservation();
         oObj.setStatus(status);
         oObj.setCheckIn(checkIn);
         oObj.setCheckOut(checkOut);
         oObj.setGuest(new Guest(guestId));
        
         
         
  
         try{
          DbConnection.startTransaction();
          DbRoomReservation dbr = new DbRoomReservation();
          dbr.insert(oObj);
          DbConnection.commitTransaction();
         }
         catch(Exception e)
         {
             DbConnection.rollbackTransaction();
         }
    }
	
	public void insertBuffer(int resId, int roomId)
	{
		RoomReservation aObj = new RoomReservation();
		Room bObj = new Room();
		
		aObj.setId(resId);
		bObj.setId(roomId);
		
		try{
			DbConnection.startTransaction();
			DbRRBuffer dbb = new DbRRBuffer();
			dbb.insertBuffer(aObj, bObj);
			DbConnection.commitTransaction();
		}
		catch(Exception e)
		{
			DbConnection.rollbackTransaction();
		}
	}

}

